#!C:\perl\bin\perl.exe
use strict;
use warnings;
use CGI qw(:standard);
use lib "/perl/lib";

my $buffer;
my $Recu;
my %FORM;

if ($ENV{'REQUEST_METHOD'} eq "POST" ) {
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	$Recu="STDIN (Methode POST)" }
else {
    $Recu="QUERY_STRING (Methode GET)";
    $buffer = $ENV{'QUERY_STRING'};
}
print "Content-type: text/html\n\n";

# Traitement et découpage.
my @pairs = split(/&/, $buffer);
foreach my $pair (@pairs) {
	(my $name,my $value) = split(/=/, $pair);
	$value =~ tr/+/ /;
	$value =~ s/%(..)/pack("C", hex($1))/eg;
	$FORM{$name} = $value;
}


print "<HTML><HEAD><TITLE>Resultat</TITLE></HEAD>\n";
print "<BODY BGCOLOR=\"#FFFFFF\">\n";

print "<H1>Résultat du traitement du formulaire</H1>\n";
print "<H2>Chaine de données reçue par le CGI</H2>\n";
print "$Recu \n<B>$buffer</B>\n";

#~ print "<H2>Liste des informations décodées</H2>\n";
#~ print "<UL>\n";

#~ foreach my $match (keys (%FORM)) {
    #~ print "<LI><B>$match: </B>".$FORM{$match};
#~ }

#~ print "</UL>\n";
print "</BODY></HTML>\n"; 

#~ print redirect("http://localhost/base_mmdn/saisie/autres_tests/test.php");
